# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/25 下午2:48
 @Author  : tgy
 
"""


def test01():
    ...
    name = 'zhangsan'
    print([ord(c) for c in name])
    print(list(map(ord, name)))


def test02():
    ...
    index = 1
    while True:
        ...
        flag = yield index * 2
        print(flag)
        if flag and flag == 1:
            break
        index += 1


def my_map(func,*args):
    ...
    # for arg in args:
    #     yield func(arg)
    # for (x,) in zip(*args):
    #     print(x)
    return (func(*arg) for arg in zip(*args))


def my_zip(*args):
    ...
    get_iters = [iter(arg) for arg in args]
    while True:
        try:
            res = [next(get_iter) for get_iter in get_iters]
            yield tuple(res)
        except Exception:
            ...
            return


def my_zip01(*args):
    iters = list(map(iter, args))
    while iters:
        try:
            # iters 为迭代对象，每次for循环中，iter(iters)都是同一个对象，也就是说这个 for循环一直使用一次性的对象进行迭代
            # res = [next(i) for i in iters]
            yield tuple(next(i) for i in iters)
        except Exception:
            return

def test03():
    ...
    print([(x,y) for x in range(10) if x > 5 for y in range(10) if y < 5])
    res = []
    for x in range(10):
        if x > 5:
            for y in range(10):
                if y < 5:
                    res.append((x,y))
    print(res)


def my_timer(func):
    def inner(*args, **kwargs):
        ...
        import time
        start = time.time()
        res = func(*args, **kwargs)
        print(time.time() - start)
        return res
    return inner


@my_timer
def test04():
    ...
    sum = 0;
    for i in range(100000):
        sum +=i
    return sum


def test05():
    import main_demo
    main_demo.test01()

if __name__ == '__main__':
    ...
    # test01()
    # gen = test02()
    # print(next(gen))
    # try:
    #     gen.send(1)
    # except Exception as e:
    #     print(e)
    # print(list(my_map(ord, 'zhangsan')))
    # test03()
    # print(list(my_zip([1, 2, 3], 'zhangsan', (4, 5, 6))))
    # print(list(my_zip01([1, 2, 3], 'zhangsan', (4, 5, 6))))
    # print(test04())
    test05()
